#!/bin/env bash

# Status Line
while true
do
# 获取音量
VOL=$(amixer get Master | sed -n '5p' | grep -Po '\d{1,3}%')

# 获取电池信息
BAT_INFO=$(acpi | sed -n '2p')
# 解析电量
BAT=$(echo $BAT_INFO | grep -Po '\d{2,3}%')
# 解析电池状态
BAT_STAT=$(echo $BAT_INFO | awk '{ print $3 }')

# 根据电量显示不同电量图标
if   [ ${BAT:0:2} -eq 100 ]
then
	BAT_ICON=""
elif [ ${BAT:0:2} -ge 90 ]
then
	BAT_ICON=""
elif [ ${BAT:0:2} -ge 80 ]
then
	BAT_ICON=""
elif [ ${BAT:0:2} -ge 70 ]
then
	BAT_ICON=""
elif [ ${BAT:0:2} -ge 60 ]
then
	BAT_ICON=""
elif [ ${BAT:0:2} -ge 50 ]
then
	BAT_ICON=""
elif [ ${BAT:0:2} -ge 40 ]
then
	BAT_ICON=""
elif [ ${BAT:0:2} -ge 30 ]
then
	BAT_ICON=""
elif [ ${BAT:0:2} -ge 20 ]
then
	BAT_ICON=""
elif [ ${BAT:0:2} -ge 10 ]
then
	BAT_ICON=""
else
	BAT_ICON=""
fi
# 设置电池状态图标
if [ $BAT_STAT = "Not" ];then
	BAT_STAT_ICON="ﮣ"
elif [ $BAT_STAT = "Discharging," ];then
	BAT_STAT_ICON="ﮤ"
else
	BAT_STAT_ICON=""
fi

# 获取当前时间
DATE=$(date --rfc-3339=seconds | grep -P '^.+?:\d{2}' -o)


# 输入至状态栏
xsetroot -name "$VOL | $BAT_STAT_ICON$BAT_ICON | $DATE" 
# 延时
sleep 1

done &
